home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBVGAL17.ARJ / SRC_C.ARJ / VESA.C next >
C/C++ Source or Header  |  1992-01-26  |  3KB  |  146 lines

  1. /* vesa.c */
  2. #define VESA
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7. #include "vidlib.h"
  8. #include "vesa.h"
  9.  
  10. int   VESAmode(unsigned int mode, char *palette)
  11. {
  12.     union REGS r;
  13.     unsigned int memory;   /* display memory, in 32 byte units */
  14.  
  15.     if (isVESAmode(0x101))
  16.        memory=16384;  /* 512k */
  17.     else
  18.        memory=8192;  /* 256k */
  19.  
  20.     r.x.ax=0x4f02;
  21.     r.x.bx=mode;
  22.     int86(0x10,&r,&r);
  23.     if ( r.h.ah == 0 ) {
  24.        if (palette != NULL)          /* if not NULL */
  25.           if (palette == DEFAULTDAC) /* restore defaults */
  26.              WriteDACs(_olddacs);
  27.           else
  28.              WriteDACs(palette);
  29.        getVESAinfo(mode);
  30.        _screen_start=(char *)0xA0000000L;
  31.        _screen_width=Vminfo.bytesperline;
  32.        _screen_length=Vminfo.YPixels;
  33.        _memory_length=(memory/(Vminfo.bytesperline/32));
  34.        _window_size=(unsigned long)Vminfo.size << 10;
  35.        VESAsetpage(0);
  36.        return(1);
  37.     } else
  38.        return(0);
  39. }
  40.  
  41. int    isVESA(void)
  42. {
  43.     union   REGS    r;
  44.     struct  SREGS   s;
  45.  
  46.     r.x.ax = 0x4F00;             /* VESA BIOS call               */
  47.     s.es = FP_SEG(&Vinfo);      /* Place address into parm list */
  48.     r.x.di= FP_OFF(&Vinfo);
  49.     int86x(0x10, &r, &r, &s);     /* Try VESA BIOS        */
  50.                     /* Check status and signature   */
  51.     if ((r.x.ax != 0x004F) ||
  52.     (strncmp(Vinfo.signature,"VESA",4) != 0) ) {
  53.     return(0);
  54.     }
  55.     return(1);
  56. }
  57.  
  58. /* returns 1 for a valid mode, 0 if not */
  59. int    isVESAmode(int mode)
  60. {
  61.      union REGS r;
  62.      struct SREGS s;
  63.  
  64.      r.h.ah=0x4f; r.h.al=0;
  65.      s.es=FP_SEG(&Vinfo);
  66.      r.x.di=FP_OFF(&Vinfo);
  67.      int86x(0x10,&r,&r,&s);
  68.      if (r.x.ax != 0x004f) {
  69.            return(0);
  70.      }
  71.      if (strncmp(Vinfo.signature,"VESA",4) == 0) {
  72.       while ((*(Vinfo.modeptr) != EOF) &&
  73.                  (*(Vinfo.modeptr) != mode) )
  74.                   Vinfo.modeptr++;
  75.           if (*Vinfo.modeptr == mode) {
  76.              return(1);
  77.           } else {
  78.              return(0);
  79.           }
  80.      }  else {
  81.           return(0);
  82.      }
  83. }
  84.  
  85. struct vesainfo *getVESAinfo(int mode)
  86. {
  87.     union REGS r;
  88.     struct SREGS s;
  89.  
  90.     r.h.ah=0x4f; r.h.al=0x01; r.x.cx=mode;
  91.     s.es=FP_SEG(&Vminfo); r.x.di=FP_OFF(&Vminfo);
  92.     int86x(0x10,&r,&r,&s);
  93.     if ( r.x.ax == 0x004F ) {
  94.        return(&Vinfo);
  95.     }  else {
  96.        return(NULL);
  97.     }
  98. }
  99.  
  100. int VESAsetpage(unsigned page) /* assume window 0 */
  101. {
  102.   return(VESAsetpagew(0, page));
  103. }
  104.  
  105. int  VESAsetpagew(char window, unsigned page)
  106. {
  107.    union REGS r;
  108.    r.x.ax=0x4f05;
  109.    r.h.bh=0;
  110.    r.h.bl=window;
  111.    r.x.dx=page;
  112.    int86(0x10,&r,&r);
  113.    if (r.h.ah == 0) {
  114.       vesapage=page;
  115.       VESAnext_break();
  116.       return(page);
  117.    } else {
  118.       return(0);
  119.    }
  120. }
  121.  
  122. int VESAsetpagewbios(char window, unsigned page)
  123. {
  124.    union REGS r;
  125.  
  126.    r.h.ah=0x4f; r.h.al=5;
  127.    r.h.bh=0;    r.h.bl=window;
  128.    r.x.dx=page;
  129.    int86(0x10,&r,&r);
  130.    vesapage=page;
  131.    VESAnext_break();
  132.    return(!r.h.ah);
  133. }
  134.  
  135. /* Vnext_break_row = the next line upon which a break occurs */
  136. /* Vnext_break_col = the byte in that line that starts the next page */
  137. void   VESAnext_break(void)
  138. {
  139.    Vnext_break_row=(unsigned int) (
  140.        (_window_size*(vesapage+1)) / (long)Vminfo.bytesperline  );
  141.    Vnext_break_col=(unsigned int) (
  142.        (_window_size*(vesapage+1)) % Vminfo.bytesperline  );
  143. }
  144.  
  145.  
  146.